﻿

namespace Huirui.Cavan.Domain.MainBoundedContext.SystemModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Huirui.Cavan.Domain.Seedwork;
    using Huirui.Cavan.Core.Extension;

    [Serializable]
    public class Area : Persistent<string>
    {
        #region Member Variables
        protected string _name;
        protected string _postcode;
        protected int _level;
        protected bool _enabled;
        protected int _sort;
        protected string _spell;
        protected string _parentcode;

        public static IList<Area> Provinces = null;
        public static IList<Area> Cities = null;   
        #endregion

        #region Constructors
        public Area() { }

        public Area(string pCode, string pName, string pPostCode, int pLevel, bool pEnabled, int pSort, DateTime pModifyDate, int pEditUser, string pSpell, DateTime pCreateDate)
        {
            this.Id = pCode;
            this._name = pName;
            this._postcode = pPostCode;
            this._level = pLevel;
            this._enabled = pEnabled;
            this._sort = pSort;
            this._spell = pSpell;
            this._modifyDate = pModifyDate;
            this._createDate = pCreateDate;
            this._editUser = pEditUser;
        }

        #endregion

        #region Public Properties

        public virtual string Name
        {
            get { return _name; }
            set
            {
                if (value != null && value.Length > 50)
                    throw new ArgumentOutOfRangeException("Name", "Name value, cannot contain more than 50 characters");
                _name = value;
            }

        }

        public virtual string PostCode
        {
            get { return _postcode; }
            set
            {
                if (value != null && value.Length > 10)
                    throw new ArgumentOutOfRangeException("PostCode", "PostCode value, cannot contain more than 10 characters");
                _postcode = value;
            }
        }

        public virtual int Level
        {
            get { return _level; }
            set { _level = value; }
        }

        public virtual bool Enabled
        {
            get { return _enabled; }
            set { _enabled = value; }
        }

        public virtual int Sort
        {
            get { return _sort; }
            set { _sort = value; }
        }


        public virtual string Spell
        {
            get { return _spell; }
            set
            {
                if (value != null && value.Length > 20)
                    throw new ArgumentOutOfRangeException("Spell", "Spell value, cannot contain more than 20 characters");
                _spell = value;
            }

        }

        public virtual string ParentCode
        {
            get { return _parentcode; }
            set { _parentcode = value; }
        }

        #endregion


        public override string ToDisplay()
        {
            return Name;
        }


        public override bool IsTransient()
        {
            return Id.IsEmpty();
        }
    }
}
